package com.trust.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trust.agri.util.BeanUtil;
import com.trust.entity.SystemPerson;
import com.trust.entity.result.PersonDropDownResult;
import com.trust.mapper.SystemPersonMapper;
import com.trust.service.SystemPersonService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SystemPersonServiceImpl extends ServiceImpl<SystemPersonMapper, SystemPerson> implements SystemPersonService{

    @Override
    public String getNameById(Integer id) {
        SystemPerson person = this.getById(id);
        if (null == person) {
            return "";
        }
        return person.getName();
    }

    @Override
    public List<PersonDropDownResult> dropDown(String keywords) {
        LambdaQueryWrapper<SystemPerson> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(keywords), SystemPerson::getName, keywords);
        wrapper.orderByDesc(SystemPerson::getId);
        List<SystemPerson> list = this.list(wrapper);
        return BeanUtil.sourceList2targetList(list, PersonDropDownResult.class);
    }

}
